package com.website.dayouziblog.response;

import com.website.dayouziblog.exception.BaseErrorEnum;

public class RespGenerator {
	/**
	 * 接口调用成功时出参
	 * 
	 * @param data
	 *            接口返回数据
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static BaseResponse returnOK(Object data) {
		return new BaseResponse(BaseErrorEnum.SUCCESS.getCode(), "接口调用成功!", data);
	}
 
	/**
	 * 调用失败：状态码，异常信息
	 * 
	 * @param code
	 *            错误码
	 * @param message
	 *            错误信息
	 * @return
	 */
	public static BaseResponse<Object> returnError(String code, String message) {
		return new BaseResponse<Object>(code, message, null);
	}
 
	/**
	 * 调用失败：异常信息
	 * 
	 * @param message
	 *            错误信息
	 * @return
	 */
	public static BaseResponse<Object> returnError(String message) {
		return new BaseResponse<Object>("-1", message, null);
	}

	/**
	 * 调用失败：BaseErrorEnum自定义异常枚举类
	 * @param e
	 * @return
	 */
	public static BaseResponse<Object> returnError(BaseErrorEnum e) {
		return new BaseResponse<Object>(e.getCode(), e.getMessage(), null);
	}
 
}